package com.example.spark.rdd;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;

import java.util.Arrays;
import java.util.List;

public class SparkRDDExample_map {
    public static void main(String[] args) {

        //创建配置对象
        SparkConf conf = new SparkConf();
        conf.setMaster("local[*]");
        conf.setAppName("spark_demo");

        //创建SparkContext
        JavaSparkContext jsc = new JavaSparkContext(conf);
        //编写逻辑代码

        List<String> datas = Arrays.asList("Java", "Python", "C", "C#", "PHP");

        JavaRDD<String> rdd1 = jsc.parallelize(datas);

        JavaRDD<String> rdd2 = rdd1.map(new Function<String, String>() {
            @Override
            public String call(String v1) throws Exception {
                return v1 + "|";
            }
        });
        List<String> collect = rdd2.collect();
        collect.forEach(s ->System.out.print(s));


        // Java|Python|C|C#|PHP|




        //关闭,回收资源
        jsc.stop();

    }



}
